<template>
  <base-breadcrumb>
    <searchData
      :search-data="searchArr"
      @search="search"
    />
    <a-card :bordered="false">
      <div class="table-operator" v-if="hideBuquBtn()">
        <a-button
          v-btn-permission="'lcm_001_add_01'"
          type="primary"
          icon="plus"
          @click="visible = true; recordId = null; isLook = false"
        >
          新增招标需求计划
        </a-button>
      </div>

      <list-table
        ref="table"
        size="default"
        row-key="id"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        show-pagination="auto"
      >
        <template
          slot="auditStatus"
          slot-scope="text, record"
        >
          <list-status
            :status="record.auditStatus"
            :text="record.auditStatusStr"
          />
        </template>
        <template
          slot="action"
          slot-scope="text, record"
        >
          <MoreButton>
            <a @click="visible = true; recordId = record.id; isLook = true">查看</a>
            <a @click="visible = true; recordId = record.id; isLook = false" v-if="hideBuquBtn()">编辑</a>
            <template v-if="record.auditStatus === 'DRAFT' || record.auditStatus === 'REJECTED'">
              <a @click="handleDel(record.id)" v-if="hideBuquBtn()">删除</a>
            </template>
          </MoreButton>
        </template>
        <div
          slot="expandedRowRender"
          slot-scope="record"
          style="margin: 0"
        >
          <p>分包工程招标内容：{{ record.biddingContent || '无' }}</p>
          <p>备注：{{ record.remark || '无' }}</p>
        </div>
      </list-table>
      <add-post
        :id="recordId"
        ref="createModal"
        :is-look="isLook"
        :visible.sync="visible"
        @ok="$refs.table.refresh(true)"
      />
    </a-card>
  </base-breadcrumb>
</template>

<script>
import { STable } from '@/components'
import {
    getTechnologyLinkage,
    getTechnologyProject,
    getBranchBiddingList,
    deleteDemandByExecutionCase
} from '@/api/legal'
import addPost from './addPost'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject'
import OrgTreeSelect from '@/components/OrgTreeSelect'
import moment from 'moment'

export default {
  name:'a'+Date.now(),
    components: {
        STable,
        addPost,
    },
    data() {
        return {
            isLook: false,
            searchArr: [
                // 搜索框
                // {
                //     name: '所属分公司',
                //     valueKey: 'branchCompanyId',
                //     type: SelectSubCompany
                // },
                // {
                //     name: '项目名称',
                //     type: SelectProject,
                //     valueKey: 'projectId'
                // },
                {
                  name: '所属单位',
                  valueKey: 'searchQuery',
                  type: OrgTreeSelect,
                },
                {
                    name: '计划进场日期',
                    value: 'plan',
                    type: 'dateRangeFormatx'
                },
                {
                    name: '创建时间',
                    value: 'create',
                    type: 'timeRangeFormatx'
                }
            ],
            columns: [
                {
                    title: '所属分公司',
                    dataIndex: 'branchCompany'
                },
                {
                    title: '项目名称',
                    dataIndex: 'projectName'
                },
                {
                    title: '计划进场时间',
                    dataIndex: 'planStartTime'
                },
                {
                    title: '计划队伍数量 ',
                    dataIndex: 'plannedTeamsNum'
                },
                {
                    title: '状态',
                    dataIndex: 'auditStatus',
                    scopedSlots: { customRender: 'auditStatus' }
                },
                {
                    title: '创建时间',
                    dataIndex: 'createTime'
                },
                {
                    title: '操作',
                    width: '160px',
                    scopedSlots: { customRender: 'action' }
                }
            ],
            visible: false,
            recordId: null,
            queryParam: {},
            loadData: (parameter) => {
                const searchData = Object.assign({}, parameter, this.queryParam)
                if (searchData.plan) {
                    searchData.planStart = moment(Number(searchData.planStart)).hour(0).minute(0).second(0).valueOf()
                    searchData.planEnd = moment(Number(searchData.planEnd)).hour(23).minute(59).second(59).valueOf()
                    searchData.planStartTime = moment(Number(searchData.planStartTime)).hour(0).minute(0).second(0).valueOf()
                    searchData.planEndTime = moment(Number(searchData.planEndTime)).hour(23).minute(59).second(59).valueOf()
                }
                return getBranchBiddingList(searchData).then((res) => {
                    return res
                })
            },
            branchCompanyList: [],
            projectList: []
        }
    },
    filters: {
        statusFilter(type) {
            return statusMap[type].text
        },
        statusTypeFilter(type) {
            return statusMap[type].status
        }
    },
    created() {
        getTechnologyLinkage().then((res) => {
            this.branchCompanyList = res.data
        })
    },
    methods: {
        handleDel(id) {
            let params = id ? [id] : this.selectId
            this.$delList2(deleteDemandByExecutionCase, () => {
                this.$refs.table.refresh(true)
            }, { ids: params })
        },
        getProject(id) {
            getTechnologyProject(id).then((res) => {
                this.projectList = res.data
            })
        },
        search(val) {
            this.queryParam = val
            this.$refs.table.refresh(true)
        }
    }
}
</script>
